1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module shumate.VectorRenderer;
26 
27 private import gio.InitableIF;
28 private import gio.InitableT;
29 private import glib.ConstructionException;
30 private import glib.ErrorG;
31 private import glib.GException;
32 private import glib.Str;
33 private import gobject.ObjectG;
34 private import shumate.DataSource;
35 private import shumate.MapSource;
36 private import shumate.c.functions;
37 public  import shumate.c.types;
38 
39 
40 /**
41  * A [class@Shumate.MapSource] that renders tiles from a given vector data source.
42  */
43 public class VectorRenderer : MapSource, InitableIF
44 {
45 	/** the main Gtk struct */
46 	protected ShumateVectorRenderer* shumateVectorRenderer;
47 
48 	/** Get the main Gtk struct */
49 	public ShumateVectorRenderer* getVectorRendererStruct(bool transferOwnership = false)
50 	{
51 		if (transferOwnership)
52 			ownedRef = false;
53 		return shumateVectorRenderer;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected override void* getStruct()
58 	{
59 		return cast(void*)shumateVectorRenderer;
60 	}
61 
62 	/**
63 	 * Sets our main struct and passes it to the parent class.
64 	 */
65 	public this (ShumateVectorRenderer* shumateVectorRenderer, bool ownedRef = false)
66 	{
67 		this.shumateVectorRenderer = shumateVectorRenderer;
68 		super(cast(ShumateMapSource*)shumateVectorRenderer, ownedRef);
69 	}
70 
71 	// add the Initable capabilities
72 	mixin InitableT!(ShumateVectorRenderer);
73 
74 
75 	/** */
76 	public static GType getType()
77 	{
78 		return shumate_vector_renderer_get_type();
79 	}
80 
81 	/**
82 	 * Creates a new [class@VectorRenderer] to render vector tiles from @data_source.
83 	 *
84 	 * Params:
85 	 *     dataSource = a [class@DataSource] to provide tile image data
86 	 *     styleJson = a vector style
87 	 *
88 	 * Returns: a newly constructed [class@VectorRenderer]
89 	 *
90 	 * Throws: GException on failure.
91 	 * Throws: ConstructionException GTK+ fails to create the object.
92 	 */
93 	public this(DataSource dataSource, string styleJson)
94 	{
95 		GError* err = null;
96 
97 		auto __p = shumate_vector_renderer_new((dataSource is null) ? null : dataSource.getDataSourceStruct(), Str.toStringz(styleJson), &err);
98 
99 		if (err !is null)
100 		{
101 			throw new GException( new ErrorG(err) );
102 		}
103 
104 		if(__p is null)
105 		{
106 			throw new ConstructionException("null returned by new");
107 		}
108 
109 		this(cast(ShumateVectorRenderer*) __p, true);
110 	}
111 
112 	/**
113 	 * Creates a new [class@VectorRenderer] that fetches tiles from the given URL
114 	 * using a [class@TileDownloader] data source.
115 	 *
116 	 * Equivalent to:
117 	 *
118 	 * ```c
119 	 * g_autoptr(ShumateTileDownloader) source = shumate_tile_downloader_new (url_template);
120 	 * ShumateVectorRenderer *renderer = shumate_vector_renderer_new (source);
121 	 * ```
122 	 *
123 	 * Params:
124 	 *     urlTemplate = a URL template to fetch tiles from
125 	 *     styleJson = a vector style
126 	 *
127 	 * Returns: a newly constructed [class@VectorRenderer]
128 	 *
129 	 * Throws: GException on failure.
130 	 * Throws: ConstructionException GTK+ fails to create the object.
131 	 */
132 	public this(string urlTemplate, string styleJson)
133 	{
134 		GError* err = null;
135 
136 		auto __p = shumate_vector_renderer_new_from_url(Str.toStringz(urlTemplate), Str.toStringz(styleJson), &err);
137 
138 		if (err !is null)
139 		{
140 			throw new GException( new ErrorG(err) );
141 		}
142 
143 		if(__p is null)
144 		{
145 			throw new ConstructionException("null returned by new_from_url");
146 		}
147 
148 		this(cast(ShumateVectorRenderer*) __p, true);
149 	}
150 
151 	/**
152 	 * Creates a new [class@VectorRenderer] to render vector tiles from @data_source.
153 	 *
154 	 * Params:
155 	 *     id = the map source's id
156 	 *     name = the map source's name
157 	 *     license = the map source's license
158 	 *     licenseUri = the map source's license URI
159 	 *     minZoom = the map source's minimum zoom level
160 	 *     maxZoom = the map source's maximum zoom level
161 	 *     tileSize = the map source's tile size (in pixels)
162 	 *     projection = the map source's projection
163 	 *     dataSource = a [class@DataSource] to provide tile image data
164 	 *
165 	 * Returns: a newly constructed [class@VectorRenderer] object
166 	 *
167 	 * Throws: GException on failure.
168 	 * Throws: ConstructionException GTK+ fails to create the object.
169 	 */
170 	public this(string id, string name, string license, string licenseUri, uint minZoom, uint maxZoom, uint tileSize, ShumateMapProjection projection, DataSource dataSource, string styleJson)
171 	{
172 		GError* err = null;
173 
174 		auto __p = shumate_vector_renderer_new_full(Str.toStringz(id), Str.toStringz(name), Str.toStringz(license), Str.toStringz(licenseUri), minZoom, maxZoom, tileSize, projection, (dataSource is null) ? null : dataSource.getDataSourceStruct(), Str.toStringz(styleJson), &err);
175 
176 		if (err !is null)
177 		{
178 			throw new GException( new ErrorG(err) );
179 		}
180 
181 		if(__p is null)
182 		{
183 			throw new ConstructionException("null returned by new_full");
184 		}
185 
186 		this(cast(ShumateVectorRenderer*) __p, true);
187 	}
188 
189 	/**
190 	 * Creates a new [class@VectorRenderer] that fetches tiles from the given URL
191 	 * using a [class@TileDownloader] data source.
192 	 *
193 	 * Params:
194 	 *     id = the map source's id
195 	 *     name = the map source's name
196 	 *     license = the map source's license
197 	 *     licenseUri = the map source's license URI
198 	 *     minZoom = the map source's minimum zoom level
199 	 *     maxZoom = the map source's maximum zoom level
200 	 *     tileSize = the map source's tile size (in pixels)
201 	 *     projection = the map source's projection
202 	 *     urlTemplate = a template for the URL to fetch tiles from
203 	 *
204 	 * Returns: a newly constructed [class@VectorRenderer] object
205 	 *
206 	 * Throws: GException on failure.
207 	 * Throws: ConstructionException GTK+ fails to create the object.
208 	 */
209 	public this(string id, string name, string license, string licenseUri, uint minZoom, uint maxZoom, uint tileSize, ShumateMapProjection projection, string urlTemplate, string styleJson)
210 	{
211 		GError* err = null;
212 
213 		auto __p = shumate_vector_renderer_new_full_from_url(Str.toStringz(id), Str.toStringz(name), Str.toStringz(license), Str.toStringz(licenseUri), minZoom, maxZoom, tileSize, projection, Str.toStringz(urlTemplate), Str.toStringz(styleJson), &err);
214 
215 		if (err !is null)
216 		{
217 			throw new GException( new ErrorG(err) );
218 		}
219 
220 		if(__p is null)
221 		{
222 			throw new ConstructionException("null returned by new_full_from_url");
223 		}
224 
225 		this(cast(ShumateVectorRenderer*) __p, true);
226 	}
227 
228 	/**
229 	 * Checks whether libshumate was compiled with vector tile support. If it was
230 	 * not, vector renderers cannot be created or used.
231 	 *
232 	 * Returns: %TRUE if libshumate was compiled with `-Dvector_renderer=true` or
233 	 *     %FALSE if it was not
234 	 */
235 	public static bool isSupported()
236 	{
237 		return shumate_vector_renderer_is_supported() != 0;
238 	}
239 }